#include"hks_type.h"
#include"_imp_Wang_def.h"
#include"hichain.h"
#include"hks_request.h"
static inline int32_t CheckBlob(const struct HksBlob *blob)
{
    if ((blob == NULL) || (blob->data == NULL) || (blob->size == 0)) {
        return HKS_ERROR_INVALID_ARGUMENT;
    }
    return HKS_SUCCESS;
}

int32_t HksClientGenerateRandom(struct HksBlob *random, const struct HksParamSet *paramSet)
{
    if (CheckBlob(random) != HKS_SUCCESS) {
        return HKS_ERROR_INVALID_ARGUMENT;
    }
    struct HksBlob inBlob = { sizeof(random->size), (uint8_t *)&(random->size) };
    return HksSendRequest(HKS_MSG_GENERATE_RANDOM, &inBlob, random, paramSet);
}

int32_t HksGenerateRandom(const struct HksParamSet *paramSet, struct HksBlob *random)
{

    if (random == NULL) {
        return HKS_ERROR_NULL_POINTER;
    }
    int32_t ret = HksClientGenerateRandom(random, paramSet);
    return ret;
}

//TODO
DLL_API_PUBLIC void destroy(hc_handle *handle){
return ;
}


// DLL_API_PUBLIC int32_t receive_data(hc_handle handle, struct uint8_buff *data)
// {
//     LOGI("Begin receive data");
//     check_ptr_return_val(handle, HC_INPUT_ERROR);
//     check_ptr_return_val(data, HC_INPUT_ERROR);
//     check_ptr_return_val(data->val, HC_INPUT_ERROR);

//     LOGI("Receive data from peer");
//     struct hichain *hichain = (struct hichain *)handle;
//     struct message receive = { 0, 0, 0 };
//     struct message send = { INFORM_MESSAGE, 0, 0 };
//     void *send_data = NULL;
//     uint32_t send_data_len = 0;
//     int32_t ret = deserialize_message(data, &receive);
//     if (ret != HC_OK) {
//         goto inform;
//     }
//     struct header_analysis nav = navigate_message(receive.msg_code);
//     ret = check_message_support(hichain, &nav, &receive);
//     if (ret != HC_OK) {
//         goto inform;
//     }
//     ret = build_object(hichain, nav.modular, !nav.is_request_msg, NULL);
//     if (ret != HC_OK) {
//         goto inform;
//     }
//     ret = proc_message(hichain, &nav, &receive, &send);
//     if (ret != HC_OK) {
//         goto inform;
//     }
//     ret = connect_message(hichain, &nav, &send);

// inform:
//     encap_inform_message(ret, &send);

//     /* serialization */
//     ret = build_send_data_by_struct(&send, &send_data, &send_data_len);
//     if (ret == HC_OK) {
//         DBG_OUT("Send data to peer");
//         hichain->cb.transmit(&hichain->identity, send_data, send_data_len);
//         FREE(send_data);
//     } else if (ret == HC_NO_MESSAGE_TO_SEND) {
//         LOGI("Had no message to send");
//         ret = HC_OK;
//     } else {
//         LOGE("build send data failed, error code is %d", ret);
//     }
//     set_result(hichain, receive.msg_code, send.msg_code, ret);

//     destroy_receive_data_struct(&receive);
//     destroy_send_data(&send);
//     LOGI("End receive data");
//     return ret; /* hc_error */
// }